/**
 * 初始化报表配置弹出窗口
 */
function initWindow_report_config() {
    var buttons = [
        {
            text: '保存',
            name: 'save',
            handler: function (self) {
            	if(q_id === "dsy_sys_config"){
                	Ext.MessageBox.alert('提示', '系统参数不允许修改');
                    return;
                }
                //保存表单数据
                var jbxxForm = Ext.ComponentQuery.query('form[name="jbxxForm"]')[0];
                if (jbxxForm.isValid()) {
                   var qTable = Ext.ComponentQuery.query('textfield[name="Q_TABLE"]')[0].getValue();
             	   var qName = Ext.ComponentQuery.query('textfield[name="Q_TITLE"]')[0].getValue();
             	   if((qTable == null || qTable =="")){
             		   Ext.MessageBox.alert('提示', '请填写表/视图或数据源sql!');
             		   return;
             	   }
                    var formData = jbxxForm.getForm().getFieldValues();
                    formData = $.extend({}, formData, jbxxForm.getValues());
                    var url;
                    if(jbxx_edit){
                    	url='/sys-report/updatejbxxInfo';
                    }else{
                    	url='/sys-report/savejbxxInfo';
                    }
                    $.post(url, {
                        detailForm: Ext.util.JSON.encode([formData])
                    }, function (data) {
                        if (data.success) {
                            Ext.toast({
                                html: "保存成功！",
                                closable: false,
                                align: 't',
                                slideInDuration: 400,
                                minWidth: 400
                            });
                            self.up('window').close();
                            reloadGrid();
                            if(jbxx_edit){
                            	//添加日志
                                saveLog('修改查询报表','BUTTON','查询报表'+qName+'修改成功');
                            }else{
                            	//添加日志
                                saveLog('新增查询报表','BUTTON','查询报表'+qName+'新增成功');
                            }
                        } else {
                        	if(jbxx_edit){
                            	//添加日志
                                saveLog('修改查询报表','BUTTON','查询报表'+qName+'修改失败');
                            }else{
                            	//添加日志
                                saveLog('新增查询报表','BUTTON','查询报表'+qName+'新增失败');
                            }
                            Ext.MessageBox.alert('提示', '保存失败!' + data.message);
                        }
                    }, 'JSON');
                }
            }
        },
        {
            text: '关闭',
            handler: function (btn) {
                btn.up('window').close();
            }
        }
    ];
    return Ext.create('Ext.window.Window', {
        title: "报表配置", // 窗口标题
        width: document.body.clientWidth * 0.9, // 窗口宽度
        height: document.body.clientHeight * 0.9, // 窗口高度
        layout: 'fit',
        maximizable: true,
        name: 'window_report_config', // 窗口标识	
        buttonAlign: 'right', // 按钮显示的位置
        modal: true, // 模式窗口，弹出窗口后屏蔽掉其他组件
        closeAction: 'destroy',//hide:单击关闭图标后隐藏，可以调用show()显示。如果是close，则会将window销毁。
        items: initWindow_report_config_contentForm(),
        buttons: buttons
    });
};

function initWindow_report_config_contentForm() {
    return Ext.create('Ext.form.Panel', {
        width: '100%',
        height: '100%',
        layout: 'fit',
        border: false,
        defaults: {
            anchor: '100%'/*,
             margin: '5 5 5 5',*/
        },
        defaultType: 'textfield',
        items: [initWindow_report_config_contentForm_tab()]
    });
};

function initWindow_report_config_contentForm_tab() {
    var configTab = Ext.create('Ext.tab.Panel', {
        anchor: '100% -17',
        border: false,
        items: [
            {
                title: '基本信息',
                scrollable: true,
                items: initWindow_report_config_contentForm_tab_jbxx(),
                listeners:{  
                       tabchange:function(_tab, _pan) {  
                          _pan.doLayout();  
                	   }  
                	 }   
            },
            {
                title: '表头配置',
                layout: 'fit',//布局为fit后， scrollable不能用
                scrollable: true,
                items: initWindow_report_config_contentForm_tab_zdpz(),
                listeners:{
    	    		activate:function(tab){
    	    		   var count = DSYGrid.getGrid("zdpzGrid").getStore().getCount();
    	    		   if(count == 0){
    	    			    //保存表单数据
    	    			    var jbxxForm = Ext.ComponentQuery.query('form[name="jbxxForm"]')[0];
    	    			    if (jbxxForm.isValid()) {
    	    			        var formData = jbxxForm.getForm().getFieldValues();
    	    			        formData = $.extend({}, formData, jbxxForm.getValues());
    	    			        var url;
    	    			        if(jbxx_edit){
    	    			        	url='/sys-report/updatejbxxInfo';
    	    			        }else{
    	    			        	url='/sys-report/savejbxxInfo';
    	    			        }
    	    			        $.post(url, {
    	    			            detailForm: Ext.util.JSON.encode([formData])
    	    			        }, function (data) {
    	    			            if (data.success) {
    	    			            	jbxx_edit = true;
    	    			            	reloadGrid();
    	    			            	var table = Ext.ComponentQuery.query('textfield[name="Q_TABLE"]')[0].getValue();
    	    	    	    		   if(table && table != null){
    	    	                    	    Ext.Ajax.request({
    	    	                        		method : 'POST',
    	    	                        		url : "/sys-report/saveFieldInfoByTable",
    	    	                        		params : {
    	    	                        			q_id: q_id,
    	    	                        			table:table
    	    	                        		},
    	    	                        		async : false,
    	    	                        		success : function(response, options) {
//    	    	                        			// 获取返回的JSON，并根据gridid，获取表头配置信息
//    	    	                        			var respText = Ext.util.JSON.decode(response.responseText);
    	    	                        			//var REPORT =  eval(respText.REPORT)[0];
    	    	                        			// 刷新表格
    	    	                                    DSYGrid.getGrid("zdpzGrid").getStore().loadPage();
    	    	                        		},
    	    	                        		failure : function(response, options) {
    	    	                        			Ext.MessageBox.minWidth = 120;
    	    	                        			Ext.Msg.alert('提示', '获取表字段信息失败！');
    	    	                        		}
    	    	                        	});
    	    	    	    			}
    	    			            } else {
    	    			                Ext.MessageBox.alert('提示', '保存基本信息失败!' + data.message);
    	    			            }
    	    			        }, 'JSON');
    	    			    }
    	    		   }
    	    		}
    	    	}
            },
            {
                title: '条件配置',
                layout: 'fit',
                scrollable: true,
                items: initWindow_report_config_contentForm_tab_tjpz(),
                listeners:{
    	    		activate:function(tab){
    	    		   var count = DSYGrid.getGrid("tjpzGrid").getStore().getCount();
    	    		   if(count == 0){
    	    			    //保存表单数据
    	    			    var jbxxForm = Ext.ComponentQuery.query('form[name="jbxxForm"]')[0];
    	    			    if (jbxxForm.isValid()) {
    	    			        var formData = jbxxForm.getForm().getFieldValues();
    	    			        formData = $.extend({}, formData, jbxxForm.getValues());
    	    			        var url;
    	    			        if(jbxx_edit){
    	    			        	url='/sys-report/updatejbxxInfo';
    	    			        }else{
    	    			        	url='/sys-report/savejbxxInfo';
    	    			        }
    	    			        $.post(url, {
    	    			            detailForm: Ext.util.JSON.encode([formData])
    	    			        }, function (data) {
    	    			            if (data.success) {
    	    			            	jbxx_edit = true;
    	    			            	reloadGrid();
    	    			            	var table = Ext.ComponentQuery.query('textfield[name="Q_TABLE"]')[0].getValue();
    	    	    	    			if(table && table != null){
    	    	                    	    Ext.Ajax.request({
    	    	                        		method : 'POST',
    	    	                        		url : "/sys-report/saveConditionInfoByTable",
    	    	                        		params : {
    	    	                        			q_id: q_id,
    	    	                        			table:table
    	    	                        		},
    	    	                        		async : false,
    	    	                        		success : function(response, options) {
    	    	                        			// 刷新表格
    	    	                                    DSYGrid.getGrid("tjpzGrid").getStore().loadPage();
    	    	                        		},
    	    	                        		failure : function(response, options) {
    	    	                        			Ext.MessageBox.minWidth = 120;
    	    	                        			Ext.Msg.alert('提示', '获取表字段信息失败！');
    	    	                        		}
    	    	                        	});
    	    	    	    			}
    	    			            
    	    			            } else {
    	    			                Ext.MessageBox.alert('提示', '保存基本信息失败!' + data.message);
    	    			            }
    	    			        }, 'JSON');
    	    			    }
    	    		   }
    	    		}
    	    	}
            }
        ]
    });
    return configTab;
};
var json_is_title = [
	                 {id: "0", code: "0", name: "不显示标题"},
	                 {id: "1", code: "1", name: "显示标题"}
	             ];
var json_unit = [
               {id: "0", code: "0", name: "不显示"},
               {id: "1", code: "1", name: "元"},
               {id: "10000", code: "10000", name: "万元"},
               {id: "100000000", code: "100000000", name: "亿元"}
           ];
var json_right_type = [
  	                 {id: "0", code: "0", name: "区划权限"},
  	                 {id: "1", code: "1", name: "用户权限"}
  	             ];
var json_right = [
                 {id: "0", code: "0", name: "不过滤"},
                 {id: "1", code: "1", name: "区划过滤"}
             ];

var json_page = [
                  {id: "0", code: "0", name: "不分页"},
                  {id: "1", code: "1", name: "分页"}
              ];

var json_sum = [
                {id: "0", code: "0", name: "合计行不计算"},
                {id: "1", code: "1", name: "合计行计算"}
            ];

var json_openrun = [
                {id: "0", code: "0", name: "不查询"},
                {id: "1", code: "1", name: "查询"}
            ];

var json_button = [
                    {id: "0", code: "0", name: "不显示"},
                    {id: "1", code: "1", name: "显示"}
                ];

/**
 * 页签：基本信息
 */
function initWindow_report_config_contentForm_tab_jbxx() {
    var form = Ext.create('Ext.form.Panel', {
        name: 'jbxxForm',
        width: '100%',
        height: '100%',
        layout: 'column',
        defaults: {
        	 margin: '5 5 5 5',
             columnWidth: .499,
             labelAlign: "right",
            //width: 315,
            labelWidth: 100//控件默认标签宽度
        },
        defaultType: 'textfield',
        items: [  {
					    fieldLabel: '<span class="required">✶</span>报表ID',
					    name: "Q_ID",
					    allowBlank: false,
					    editable: false,
					    hidden:true
					},
                    {
                        fieldLabel: '<span class="required">✶</span>报表标题',
                        name: "Q_TITLE",
                        allowBlank: false
                    },
                    {
                    	xtype:"combobox",
                        fieldLabel: '<span class="required">✶</span>显示标题',
                        name: "Q_IS_TITLE",
                        allowBlank: false,
	            		store:  DebtEleStore(json_is_title),
	            		queryMode: 'local',
	            		editable: false,
	            		allowBlank:false,
	            		value : 1,
	            		displayField: 'name',
	            		valueField: 'id'
                    },
                    {
                    	xtype:'textareafield',
                        fieldLabel: '数据集',
                        columnWidth: .99,
                        name: "Q_TABLE",
                        allowBlank: true
                    },
                    {
                        fieldLabel: '报表说明',
                        name: "Q_REMARK"
                    },
                    {
	            		 xtype:"combobox",
	            		 fieldLabel: '<span class="required">✶</span>金额单位',
	            		 name:"MONEY_UNIT",
	            		 store:  DebtEleStore(json_unit),
	            		 queryMode: 'local',
	            		 editable: false,
	            		 allowBlank:false,
	            		 value : 1,
	            		 displayField: 'name',
	            		 valueField: 'id'	   
                 	},
                 	{
	            		 xtype:"combobox",
	            		 fieldLabel: '<span class="required">✶</span>权限过滤',
	            		 name:"Q_IS_RIGHT",
	            		 store: DebtEleStore(json_right_type),
	            		 queryMode: 'local',
	            		 editable: false,
	            		 allowBlank:false,
	            		 value : 0,
	            		 displayField: 'name',
	            		 valueField: 'id'	   
                	},
                	{
	            		 xtype:"combobox",
	            		 fieldLabel: '<span class="required">✶</span>数据分页',
	            		 name:"Q_IS_PAGE",
	            		 store: DebtEleStore(json_page),
	            		 queryMode: 'local',
	            		 editable: false,
	            		 allowBlank:false,
	            		 value : 1,
	            		 displayField: 'name',
	            		 valueField: 'id'	   
                	},
                	{
	            		 xtype:"combobox",
	            		 fieldLabel: '<span class="required">✶</span>数据合计行',
	            		 name:"Q_IS_SUM",
	            		 store: DebtEleStore(json_sum),
	            		 queryMode: 'local',
	            		 editable: false,
	            		 allowBlank:false,
	            		 value : 0,
	            		 displayField: 'name',
	            		 valueField: 'id'	   
               	    },
               	    {
	            		 xtype:"combobox",
	            		 fieldLabel: '<span class="required">✶</span>打开即查询',
	            		 name:"Q_IS_OPENRUN",
	            		 store: DebtEleStore(json_openrun),
	            		 queryMode: 'local',
	            		 editable: false,
	            		 allowBlank:false,
	            		 value : 0,
	            		 displayField: 'name',
	            		 valueField: 'id'	   
              	    },
              	    {
	            		 xtype:"combobox",
	            		 fieldLabel: '<span class="required">✶</span>常用按钮',
	            		 name:"Q_IS_BUTTON",
	            		 store: DebtEleStore(json_button),
	            		 queryMode: 'local',
	            		 editable: false,
	            		 allowBlank:false,
	            		 value : 1,
	            		 displayField: 'name',
	            		 valueField: 'id'	   
             	    }
                ]
    });
    
    if(!jbxx_edit){
    	form.down('textfield[name="Q_ID"]').setValue(q_id);
    }
    return form;
};

/**
 * 页签：字段配置
 * @returns {Ext.form.Panel}
 */
function initWindow_report_config_contentForm_tab_zdpz() {
    return Ext.create('Ext.form.Panel', {
        name: 'zdpzForm',
        width: '100%',
        height: '100%',
        layout: 'fit',
        border: false,
        padding: '0 10 0 10',
        defaultType: 'textfield',
        items: [initWindow_zqxxtb_contentForm_tab_zdpz_grid()]
    });
}

/**
 * 初始化字段配置的表格
 */
function initWindow_zqxxtb_contentForm_tab_zdpz_grid() {
    var headerJson = [
        {dataIndex: "F_ID", type: "string", hidden:true,text: "字段ID", width: 200},
        {
        	dataIndex: "Q_ID", type: "string",hidden:true,text: "报表ID", width: 100
        },
        {
        	dataIndex: "FIELD_CODE", type: "string",text: "数据列编码", width: 140
        },
        {
        	dataIndex: "FIELD_TITLE", type: "string",text: "数据列名称", width: 150
        },
        {
        	dataIndex: "FIELD_TYPE", type: "string", hidden:true,text: "数据列类型", width: 100
        },
        {
        	dataIndex: "FIELD_TYPE_NAME", type: "string", text: "数据列类型", width: 100
        },
        {
        	dataIndex: "DATA_URL", type: "string", text: "超级链接", width: 180
        },
        {
        	dataIndex: "DATA_URL_FIELD", type: "string", text: "超级链接数据列", width: 150
        },
        {
        	dataIndex: "URL_TYPE", type: "string", hidden:true,text: "链接打开方式", width: 100
        },
        {
        	dataIndex: "URL_TYPE_NAME", type: "string", text: "链接打开方式", width: 100
        },
        {
        	dataIndex: "IS_SHOW", type: "string", hidden:true,text: "列是否可见", width: 130
        },
        {
        	dataIndex: "IS_SHOW_NAME", type: "string", text: "列是否可见", width: 130
        },
        {
        	dataIndex: "IS_URL_PARAM", type: "string", hidden:true,text: "是否超链接参数", width: 120
        },
        {
        	dataIndex: "IS_URL_PARAM_NAME", type: "string", text: "是否超链接参数", width: 120
        },
        {
        	dataIndex: "IS_SUM", type: "string", hidden:true,text: "是否汇总列", width: 100
        },
        {
        	dataIndex: "IS_SUM_NAME", type: "string", text: "是否汇总列", width: 100
        },
        {
        	dataIndex: "IS_NEWLINE", type: "string",hidden:true, text: "列是否自动换行", width: 120
        },
        {
        	dataIndex: "IS_NEWLINE_NAME", type: "string", text: "列是否自动换行", width: 120
        },
        {
        	dataIndex: "SORT_INDEX", type: "string", text: "显示排序", width: 100
        },
        {
        	dataIndex: "FIELD_LENGTH", type: "string", text: "列宽", width: 100
        }
    ];
    /**
     * 设置表格属性
     */
    var config = {
        itemId: 'zdpzGrid',
        border: false,
        flex: 1,
        checkBox: false,
        headerConfig: {
            headerJson: headerJson,
            columnAutoWidth: false
        },
        autoLoad:false,
        dataUrl:'/sys-report/getQueryField?q_id='+q_id,
        pageConfig: {
            enablePage: false
        },
        rowNumber: {
            rowNumber: false// 显示行号
        },
        plugins: [
            {
                ptype: 'cellediting',
                clicksToEdit: 1,
                pluginId: 'zdpzCellEdit',
                clicksToMoveEditor: 1,
                listeners: {
                    'beforeedit': function (editor, context) {
                    },
                    'validateedit': function (editor, context) {
                    },
                    'edit': function (editor, context) {
                    	
                    }
                }
            }
        ]
    };
    //生成表格
    var grid = DSYGrid.createGrid(config);
        //将增加删除按钮添加到表格中
        grid.addDocked({
            xtype: 'toolbar',
            layout: 'column',
            items: [
                '->',
                {
                    xtype: 'button',
                    text: '新增',
                    width: 60,
                    handler: function (btn) {
                    	 if(q_id === "dsy_sys_config"){
                         	Ext.MessageBox.alert('提示', '系统参数不允许添加');
                             return;
                         }
                    	var data = {
                    			F_ID:GUID.createGUID(),
                    			Q_ID: q_id
                            };
                    	initWindow_zdpz_addOrUpdate({
                      		 title: '表头配置添加',
                      		 url:'/sys-report/savezdpzInfo',
                      		 data:data
                      	 });
                    }
                },
                {
                    xtype: 'button',
                    text: '修改',
                    itemId: 'zdpzEditBtn',
                    disabled: true,
                    handler: function (btn) {
                    	if(q_id === "dsy_sys_config"){
                        	Ext.MessageBox.alert('提示', '系统参数不允许修改');
                            return;
                        }
                    	var record = DSYGrid.getGrid('zdpzGrid').getCurrentRecord();
                        if (record==null) {
                            Ext.MessageBox.alert('提示', '请选择一条数据再进行操作');
                            return;
                        }
                        var data = record.getData();
                    	initWindow_zdpz_addOrUpdate({
                    		title: '表头配置修改',
                    		url:'/sys-report/updatezdpzInfo',
                    		edit:true,
                   		    data:data
                   	 	 });
                    }
                },
                {
                    xtype: 'button',
                    itemId: 'zdpzDelBtn',
                    text: '删除',
                    width: 60,
                    disabled: true,
                    handler: function (btn) {
                    	 if(q_id === "dsy_sys_config"){
                         	Ext.MessageBox.alert('提示', '系统参数不允许删除');
                             return;
                         }
                     	// 检验是否选中数据
                    	 var record = DSYGrid.getGrid('zdpzGrid').getCurrentRecord();
                          if (record==null) {
                              Ext.MessageBox.alert('提示', '请选择至少一条后再进行操作');
                              return;
                          }
                          Ext.Msg.confirm('提示', '请确认是否删除！', function (btn_confirm) {
                              if (btn_confirm == 'yes') {
                                  var f_id = record.get("F_ID");
                                  //发送ajax请求，删除数据
                                  $.post("/sys-report/deletezdpzData", {
                                	  f_id: f_id
                                  }, function (data) {
                                      if (data.success) {
                                          Ext.toast({
                                              html: "删除成功！",
                                              closable: false,
                                              align: 't',
                                              slideInDuration: 400,
                                              minWidth: 400
                                          });
                                       // 刷新表格
                                          DSYGrid.getGrid("zdpzGrid").getStore().loadPage();
                                      } else {
                                          Ext.MessageBox.alert('提示', '删除失败！' + data.message);
                                      }
                                  }, "json");
                              }
                          });
                      
                     
                    }
                }
            ]
        }, 0);
        grid.on('selectionchange', function (view, records) {
            grid.down('#zdpzDelBtn').setDisabled(!records.length);
            grid.down('#zdpzEditBtn').setDisabled(!records.length);
        });
    return grid;
}



/**
 * 页签：条件配置
 * @returns {Ext.form.Panel}
 */
function initWindow_report_config_contentForm_tab_tjpz() {
    return Ext.create('Ext.form.Panel', {
        name: 'tjpzForm',
        width: '100%',
        height: '100%',
        layout: 'fit',
        border: false,
        padding: '0 10 0 10',
        defaultType: 'textfield',
        items: [
                    initWindow_zqxxtb_contentForm_tab_tjpz_grid()
        ]
    });
}

/**
 * 初始化债券信息填报弹出窗口中的项目收益标签页中的表格
 */
function initWindow_zqxxtb_contentForm_tab_tjpz_grid() {
    var headerJson = [{dataIndex: "C_ID", type: "string", hidden:true,text: "条件ID", width: 200},
                      {
                      	dataIndex: "Q_ID", type: "string",hidden:true,text: "报表ID", width: 100
                      },
                      {
                      	dataIndex: "C_CODE", type: "string",text: "控件编码", width: 120
                      },
                      {
                      	dataIndex: "C_TITLE", type: "string", text: "控件名称", width: 150
                      },
                      {
                        	dataIndex: "C_FIELD_CODE", type: "string",text: "查询列", width: 120
                      },
                      {
                      	dataIndex: "C_DISP_MODE", type: "string", text: "控件类型", width: 120
                      },
                      {
                        	dataIndex: "IS_MUL", type: "string",hidden:true, text: "是否多选", width: 140
                       },
                       {
                          dataIndex: "IS_MUL_NAME", type: "string", text: "是否多选", width: 140
                       },
                      {
                      	dataIndex: "IS_MUST_INPUT", type: "string", hidden:true,text: "允许为空", width: 100
                      },
                      {
                        dataIndex: "IS_MUST_INPUT_NAME", type: "string", text: "允许为空", width: 100
                      },
                      {
                      	dataIndex: "IS_RIGHT", type: "string", hidden:true,text: "权限过滤", width: 150
                      },
                      {
                        dataIndex: "IS_RIGHT_NAME", type: "string", text: "权限过滤", width: 150
                      },
                      {
                      	dataIndex: "C_DATA_MODEL", type: "string", text: "枚举项", width: 180
                      },
                      {
                      	dataIndex: "C_DATA_SOURCE", type: "string", text: "数据集", width: 130
                      },
                      {
                      	dataIndex: "C_DATA_VALUE", type: "string", text: "控件默认值", width: 120
                      },
                      {
                      	dataIndex: "QUERY_RELATION", type: "string", text: "查询关系符", width: 100
                      },
                      {
                      	dataIndex: "SORT_INDEX", type: "string", text: "条件显示排序", width: 120
                      },
                      {
                      	dataIndex: "C_TIPS", type: "string", text: "控件tips提示", width: 160
                      },
                      {
                      	dataIndex: "C_SRC_ID", type: "string", text: "依赖查询控件编码", width: 120
                      },
                      {
                        dataIndex: "IS_SHOW", type: "string", hidden:true,text: "控件是否可见", width: 140
                      },
                      {
                        dataIndex: "IS_SHOW_NAME", type: "string", text: "控件是否可见", width: 140
                      }
                      ];
    /**
     * 设置表格属性
     */
    var config = {
        itemId: 'tjpzGrid',
        border: false,
        flex: 1,
        checkBox: false,
        headerConfig: {
            headerJson: headerJson,
            columnAutoWidth: false
        },
        autoLoad:false,
        dataUrl:'/sys-report/getQueryCondition?q_id='+q_id,
        pageConfig: {
            enablePage: false
        },
        rowNumber: {
            rowNumber: false// 显示行号
        },
        plugins: [
            {
                ptype: 'cellediting',
                clicksToEdit: 1,
                pluginId: 'tjpzCellEdit',
                clicksToMoveEditor: 1,
                listeners: {
                    'beforeedit': function (editor, context) {
                    },
                    'validateedit': function (editor, context) {
                    },
                    'edit': function (editor, context) {
                    	
                    }
                }
            }
        ]
    };
    //生成表格
    var grid = DSYGrid.createGrid(config);
        //将增加删除按钮添加到表格中
        grid.addDocked({
            xtype: 'toolbar',
            layout: 'column',
            items: [
                '->',
                {
                    xtype: 'button',
                    text: '新增',
                    width: 60,
                    handler: function (btn) {
                    	if(q_id === "dsy_sys_config"){
                         	Ext.MessageBox.alert('提示', '系统参数不允许添加');
                             return;
                         }
                    	var data = {
                    			C_ID:GUID.createGUID(),
                    			Q_ID: q_id
                            };
                    	initWindow_tjpz_addOrUpdate({
                      		 title: '条件配置添加',
                      		 url:'/sys-report/savetjpzInfo',
                      		 data:data
                      	 });
                    }
                },
                {
                    xtype: 'button',
                    text: '修改',
                    itemId: 'tjpzEditBtn',
                    disabled: true,
                    handler: function (btn) {
                    	if(q_id === "dsy_sys_config"){
                         	Ext.MessageBox.alert('提示', '系统参数不允许修改');
                             return;
                         }
                    	var record = DSYGrid.getGrid('tjpzGrid').getCurrentRecord();
                        if (record==null) {
                            Ext.MessageBox.alert('提示', '请选择一条数据再进行操作');
                            return;
                        }
                        var data = record.getData();
                    	initWindow_tjpz_addOrUpdate({
                    		title: '条件配置修改',
                    		url:'/sys-report/updatetjpzInfo',
                    		edit:true,
                   		    data:data
                   	 	 });
                    }
                },
                {
                    xtype: 'button',
                    itemId: 'tjpzDelBtn',
                    text: '删除',
                    width: 60,
                    disabled: true,
                    handler: function (btn) {
                    	if(q_id === "dsy_sys_config"){
                         	Ext.MessageBox.alert('提示', '系统参数不允许删除');
                             return;
                         }
                     	// 检验是否选中数据
                    	 var record = DSYGrid.getGrid('tjpzGrid').getCurrentRecord();
                          if (record==null) {
                              Ext.MessageBox.alert('提示', '请选择至少一条后再进行操作');
                              return;
                          }
                          Ext.Msg.confirm('提示', '请确认是否删除！', function (btn_confirm) {
                              if (btn_confirm == 'yes') {
                                  var c_id = record.get("C_ID");
                                  //发送ajax请求，删除数据
                                  $.post("/sys-report/deletetjpzData", {
                                	  c_id: c_id
                                  }, function (data) {
                                      if (data.success) {
                                          Ext.toast({
                                              html: "删除成功！",
                                              closable: false,
                                              align: 't',
                                              slideInDuration: 400,
                                              minWidth: 400
                                          });
                                       // 刷新表格
                                          DSYGrid.getGrid("tjpzGrid").getStore().loadPage();
                                      } else {
                                          Ext.MessageBox.alert('提示', '删除失败！' + data.message);
                                      }
                                  }, "json");
                              }
                          });
                    }
                }
            ]
        }, 0);
        grid.on('selectionchange', function (view, records) {
            grid.down('#tjpzDelBtn').setDisabled(!records.length);
            grid.down('#tjpzEditBtn').setDisabled(!records.length);
        });
    return grid;
};


function loadInfo(REPORT,REPORT_FIELD,REPORT_CONDITION) {
    //获取基本信息页签表单
    var jbqkForm = Ext.ComponentQuery.query('form[name="jbxxForm"]')[0];
    //加载基本情况页签表单
    jbqkForm.getForm().setValues(REPORT);

    //加载字段配置页签表格
    var zdpzGrid = DSYGrid.getGrid('zdpzGrid');
    zdpzGrid.getStore().removeAll();
    zdpzGrid.insertData(null, REPORT_FIELD);
    
  //加载条件配置页签表格
    var tjpzGrid = DSYGrid.getGrid('tjpzGrid');
    tjpzGrid.getStore().removeAll();
    tjpzGrid.insertData(null, REPORT_CONDITION);
};



/**
 * 初始化表头信息弹出窗口
 */
function initWindow_zdpz_addOrUpdate(config) {
    //弹出弹出框
   Ext.create('Ext.window.Window', {
       title: config.title, // 窗口标题
       width: 800, // 窗口宽度
       height: 370, // 窗口高度
       layout: 'fit',
       maximizable: true,
       itemId: 'window_zdpz_addOrUpdate', // 窗口标识
       buttonAlign: 'right', // 按钮显示的位置
       modal: true, // 模式窗口，弹出窗口后屏蔽掉其他组件
       closeAction: 'destroy',//hide:单击关闭图标后隐藏，可以调用show()显示。如果是destroy，则会将window销毁。
       items: initWindow_zdpz_addOrUpdate_contentForm(config),
       buttons: [
           {
               xtype: 'button',
               text: '保存',
               handler: function (self) {
                   var form = self.up('window').down('form');
                   if (form.isValid()) {
                       var formData = form.getForm().getFieldValues();
                       formData = $.extend({}, formData, form.getValues());
                       $.post(config.url, {
                           detailForm: Ext.util.JSON.encode([formData])
                       }, function (data) {
                           if (data.success) {
                               Ext.toast({
                                   html: "保存成功！",
                                   closable: false,
                                   align: 't',
                                   slideInDuration: 400,
                                   minWidth: 400
                               });
                               self.up('window').close();
                               // 刷新表格
                               DSYGrid.getGrid("zdpzGrid").getStore().loadPage();
                           } else {
                               Ext.MessageBox.alert('提示', '保存失败!' + data.message);
                           }
                       }, 'JSON');
                   }
               }
           },
           {
               xtype: 'button',
               text: '取消',
               handler: function (self) {
                   self.up('window').close();
               }
           }
       ]
   }).show();
};


var json_field_type = [
                    {id: "string", code: "string", name: "左对齐字符"},
                    {id: "rstring", code: "rstring", name: "右对齐字符"},
                    {id: "float", code: "float", name: "浮点数字"},
                    {id: "int", code: "int", name: "整数"}
                ];

var json_url_type = [
                     {id: "0", code: "0", name: "新窗口"},
                     {id: "1", code: "1", name: "对话框"}
                 ]; 

var json_show_type = [
                      {id: "0", code: "0", name: "不可见"},
                      {id: "1", code: "1", name: "可见"}
                  ];  

var json_url_param_type = [
						{id: "0", code: "0", name: "非超链接参数"},
						{id: "1", code: "1", name: "超链接参数"}
                       ]; 

var json_sum_type = [
                     {id: "0", code: "0", name: "合计行不显示"},
                     {id: "1", code: "1", name: "合计行显示"}
                 ];

var json_newline_type = [
                         {id: "0", code: "0", name: "不换行"},
                         {id: "1", code: "1", name: "自动换行"}
                     ];	

function initWindow_zdpz_addOrUpdate_contentForm(config) {
    var form = Ext.create('Ext.form.Panel', {
        width: '100%',
        height: '100%',
        itemId: 'window_zdpz_contentForm',
        layout: 'column',
        defaultType: 'textfield',
        defaults: {
            margin: '5 5 5 5',
            columnWidth: .499,
            labelAlign: "right",
            labelWidth: 110//控件默认标签宽度
        },
        items: [
				{
					xtype:'displayfield',
				    fieldLabel: '<span class="required">✶</span>字段ID',
				    name: 'F_ID',
				    hidden:true,
				    allowBlank: false
				},
                {
					xtype:'displayfield',
				    fieldLabel: '<span class="required">✶</span>报表ID',
				    name: 'Q_ID',
				    hidden:true,
				    allowBlank: false
				},
                {
					xtype: 'combobox',
				    fieldLabel: '<span class="required">✶</span>数据列编码',
				    name: 'FIELD_CODE',
				    displayField: 'name',
                    valueField: 'id',
                    store: fieldCodeStore(q_id),
                    editable: true,
				    allowBlank: false,
				    listeners: { 
	            		 'expand':function(self , eOpts ){
	            			 self.getStore().load();
	            		 },
	            		 select:function(combo, record,index){
	            			 fieldConfig();
                    	}
	                  }
				},
				{
				    fieldLabel: '<span class="required">✶</span>数据列名称',
				    name: 'FIELD_TITLE',
				    allowBlank: false
				},
				{
					xtype: 'combobox',
				    fieldLabel: '<span class="required">✶</span>数据列类型',
				    name: 'FIELD_TYPE',
				    displayField: 'name',
                    valueField: 'id',
                    value: 'string',
                    store: DebtEleStore(json_field_type),
                    editable: false,
				    allowBlank: false
				},
				{
				    fieldLabel: '超级链接',
				    name: 'DATA_URL',
				    allowBlank: true//允许为空
				},
				{
				    fieldLabel: '超级链接数据列',
				    name: 'DATA_URL_FIELD',
				    allowBlank: true//允许为空
				},
				{
					xtype: 'combobox',
				    fieldLabel: '链接打开方式',
				    name: 'URL_TYPE',
				    displayField: 'name',
				    valueField: 'id',
                    store: DebtEleStore(json_url_type),
				    allowBlank: true//允许为空
				},
				{
					xtype: 'combobox',
				    fieldLabel: '<span class="required">✶</span>列是否可见',
				    name: 'IS_SHOW',
				    displayField: 'name',
				    valueField: 'id',
				    value:1,
                    store: DebtEleStore(json_show_type),
                    editable: false,
				    allowBlank: false//允许为空
				},
				{
					xtype: 'combobox',
				    fieldLabel: '<span class="required">✶</span>是否超链接参数',
				    name: 'IS_URL_PARAM',
				    displayField: 'name',
				    valueField: 'id',
				    value:0,
				    store: DebtEleStore(json_url_param_type),
				    editable: false,
				    allowBlank: false//允许为空
				},
				{
					xtype: 'combobox',
				    fieldLabel: '<span class="required">✶</span>是否汇总列',
				    name: 'IS_SUM',
				    displayField: 'name',
				    valueField: 'id',
				    value:0,
				    store: DebtEleStore(json_sum_type),
				    editable: false,
				    allowBlank: false//允许为空
				},
				{
					xtype: 'combobox',
				    fieldLabel: '<span class="required">✶</span>列是否自动换行',
				    name: 'IS_NEWLINE',
				    displayField: 'name',
				    valueField: 'id',
				    value:0,
				    store: DebtEleStore(json_newline_type),
				    editable: false,
				    allowBlank: false//允许为空
				},
				{
					xtype:'numberfield',
				    fieldLabel: '<span class="required">✶</span>显示排序',
				    name: 'SORT_INDEX',
				    minValue:0,
				    allowBlank: false//允许为空
				},
				{
					xtype:'numberfield',
				    fieldLabel: '<span class="required">✶</span>列宽',
				    name: 'FIELD_LENGTH',
				    minValue:1,
				    allowBlank: false//允许为空
				}
        ]
    });
    if(config.edit){
    	form.down('combobox[name="FIELD_CODE"]').setDisabled(true);
    }
    //初始化及回显
    form.getForm().setValues(config.data);
    return form;
};

/**
 * 初始化条件弹出窗口
 */
function initWindow_tjpz_addOrUpdate(config) {
    //弹出弹出框
   Ext.create('Ext.window.Window', {
       title: config.title, // 窗口标题
       width: 800, // 窗口宽度
       height: 390, // 窗口高度
       layout: 'fit',
       maximizable: true,
       itemId: 'window_zdpz_addOrUpdate', // 窗口标识
       buttonAlign: 'right', // 按钮显示的位置
       modal: true, // 模式窗口，弹出窗口后屏蔽掉其他组件
       closeAction: 'destroy',//hide:单击关闭图标后隐藏，可以调用show()显示。如果是destroy，则会将window销毁。
       items: initWindow_tjpz_addOrUpdate_contentForm(config),
       buttons: [
           {
               xtype: 'button',
               text: '保存',
               handler: function (self) {
                   var form = self.up('window').down('form');
                   if (form.isValid()) {
                       var formData = form.getForm().getFieldValues();
                       formData = $.extend({}, formData, form.getValues());
                       if(config.edit){
                    	   formData.BUSI_CODE = config.data.BUSI_CODE;
                       }
                       var cDispMode = Ext.ComponentQuery.query('combobox[name="C_DISP_MODE"]')[0].getValue();
                       if(cDispMode == 'treecombobox'){
                    	   var cDataSource = Ext.ComponentQuery.query('textfield[name="C_DATA_SOURCE"]')[0].getValue();
                    	   if(cDataSource == null || cDataSource ==""){
                    		   Ext.MessageBox.alert('提示', '请填写查询数据源!');
                    		   return;
                    	   }
                       }else if(cDispMode == 'combobox'){
                    	   var cDataModel = Ext.ComponentQuery.query('textfield[name="C_DATA_MODEL"]')[0].getValue();
                    	   var cDataSource = Ext.ComponentQuery.query('textfield[name="C_DATA_SOURCE"]')[0].getValue();
                    	   if((cDataModel == null || cDataModel =="")&&(cDataSource == null || cDataSource =="")){
                    		   Ext.MessageBox.alert('提示', '请填写枚举值或查询数据源!');
                    		   return;
                    	   }
                       }
                       $.post(config.url, {
                           detailForm: Ext.util.JSON.encode([formData])
                       }, function (data) {
                           if (data.success) {
                               Ext.toast({
                                   html: "保存成功！",
                                   closable: false,
                                   align: 't',
                                   slideInDuration: 400,
                                   minWidth: 400
                               });
                               self.up('window').close();
                               // 刷新表格
                               DSYGrid.getGrid("tjpzGrid").getStore().loadPage();
                           } else {
                               Ext.MessageBox.alert('提示', '保存失败!' + data.message);
                           }
                       }, 'JSON');
                   }
               }
           },
           {
               xtype: 'button',
               text: '取消',
               handler: function (self) {
                   self.up('window').close();
               }
           }
       ]
   }).show();
};


var json_must_type = [
                    {id: "0", code: "0", name: "允许为空"},
	                {id: "1", code: "1", name: "不允许为空"}
                ];

var json_mul = [
                {id: "0", code: "0", name: "单选"},
                {id: "1", code: "1", name: "多选"}
            ]; 

var json_disp_mode_type = [
                           {id: "textfield", code: "textfield", name: "文本框"},
                           {id: "combobox", code: "combobox", name: "下拉框"},
                           {id: "datefield", code: "datefield", name: "日期"},
                           {id: "treecombobox", code: "treecombobox", name: "下拉树"},
                           {id: "label", code: "label", name: "描述框"},
                           {id: "numberfield", code: "numberfield", name: "数值"}
                       ];

var json_query_relation = [
                           {id: "like", code: "like", name: "like"},
                           {id: "in", code: "in", name: "in"},
                           {id: "=", code: "=", name: "="},
                           {id: "<=", code: "<=", name: "<="},
                           {id: ">=", code: ">=", name: ">="},
                           {id: ">", code: ">", name: ">"},
                           {id: "<", code: "<", name: "<"},
                           {id: "rlike", code: "rlike", name: "like%"},
                           {id: "llike", code: "llike", name: "%like"}
                       ];

function initWindow_tjpz_addOrUpdate_contentForm(config) {
    var form = Ext.create('Ext.form.Panel', {
        width: '100%',
        height: '100%',
        itemId: 'window_tjpz_contentForm',
        layout: 'column',
        defaultType: 'textfield',
        defaults: {
            margin: '5 5 5 5',
            columnWidth: .499,
            labelAlign: "right",
            labelWidth: 110//控件默认标签宽度
        },
        items: [
				{
					xtype:'displayfield',
				    fieldLabel: '<span class="required">✶</span>条件ID',
				    name: 'C_ID',
				    hidden:true,
				    allowBlank: false
				},
                {
					xtype:'displayfield',
				    fieldLabel: '<span class="required">✶</span>报表ID',
				    name: 'Q_ID',
				    hidden:true,
				    allowBlank: false
				},
                {
				    xtype: 'combobox',
					fieldLabel: '<span class="required">✶</span>控件编码',
				    name: 'C_CODE',
				    displayField: 'name',
                    valueField: 'id',
                    store: conditionCodeStore(q_id),
                    editable: true,
				    allowBlank: false,
				    listeners: { 
	            		 'expand':function(self , eOpts ){
	            			 self.getStore().load();
	            		 },
	            		 select:function(combo, record,index){
	            			 conditionConfig();
                    	}
	                  }
				},
				{
				    fieldLabel: '<span class="required">✶</span>控件名称',
				    name: 'C_TITLE',
				    allowBlank: false
				},
				{
				    fieldLabel: '<span class="required">✶</span>查询列',
				    name: 'C_FIELD_CODE',
				    allowBlank: false
				},
				{
					xtype: 'combobox',
				    fieldLabel: '<span class="required">✶</span>控件类型',
				    name: 'C_DISP_MODE',
				    displayField: 'name',
                    valueField: 'id',
                    value: 'textfield',
                    store: DebtEleStore(json_disp_mode_type),
                    editable: false,
				    allowBlank: false,
				    listeners:{  
                       select:function(combo, record,index){
                    	var modeValue =  Ext.ComponentQuery.query('combobox[name="C_DISP_MODE"]')[0].getValue();
                    	var queryRelation = Ext.ComponentQuery.query('combobox[name="QUERY_RELATION"]')[0]
                    	var isMul = Ext.ComponentQuery.query('combobox[name="IS_MUL"]')[0];
                    	if(modeValue == "treecombobox"){
                    		isMul.setHidden(false);
                    	}else{
                    		isMul.setValue("0");
                    		isMul.setHidden(true);
                    	}
                    	if(modeValue == "label"){
	                    		queryRelation.setValue("");
	                    		queryRelation.setDisabled(true);
	                    	}else{
	                    		queryRelation.setDisabled(false);
	                    	}
                    	}
                     }
				},
				{
					xtype: 'combobox',
				    fieldLabel: '<span class="required">✶</span>是否多选',
				    name: 'IS_MUL',
				    displayField: 'name',
                    valueField: 'id',
                    value: 0,
                    hidden:true,
                    store: DebtEleStore(json_mul),
                    editable: false,
				    allowBlank: false
				},
				{
					xtype: 'combobox',
				    fieldLabel: '<span class="required">✶</span>允许为空',
				    name: 'IS_MUST_INPUT',
				    displayField: 'name',
                    valueField: 'id',
                    value: 0,
                    store: DebtEleStore(json_must_type),
                    editable: false,
				    allowBlank: false
				},
				{
					xtype: 'combobox',
				    fieldLabel: '<span class="required">✶</span>权限过滤',
				    name: 'IS_RIGHT',
				    displayField: 'name',
				    valueField: 'id',
                    value: 0,
                    store: DebtEleStore(json_right),
                    editable: false,
				    allowBlank: false//允许为空
				},
				{
				    fieldLabel: '枚举项',
				    name: 'C_DATA_MODEL',
				    allowBlank: true,
				    validator:function(val) {
					     if (!Ext.isEmpty(val)) {
				    		 var keyValues = val.split("+");
					    	 for (var i = 0; i < keyValues.length; i++){
					    	     var keyValue = keyValues[i];
					    	     var key_value = keyValue.split("#");
					    	     if(key_value.length != 2 || key_value[1] == undefined||key_value[1] == null ||key_value[1] == ""){//undefined
						    		 return "格式不正确,请输入正确的值:key#value+key1#value1";
						    	 }
					    	  } 
				    	 
					     }
					   return true;
					   }
				},
				{
				    fieldLabel: '数据集',
				    name: 'C_DATA_SOURCE',
				    allowBlank: true
				},
				{
				    fieldLabel: '控件默认值',
				    name: 'C_DATA_VALUE',
				    allowBlank: true
				},
				{
					xtype: 'combobox',
				    fieldLabel: '<span class="required">✶</span>查询关系符',
				    name: 'QUERY_RELATION',
				    displayField: 'name',
                    valueField: 'id',
                    value: 'like',
                    store: DebtEleStore(json_query_relation),
                    editable: false,
				    allowBlank: false
				},
				{
					xtype:'numberfield',
				    fieldLabel: '<span class="required">✶</span>显示排序',
				    name: 'SORT_INDEX',
				    minValue:1,
				    allowBlank: false
				},
				{
				    fieldLabel: '控件tips提示',
				    name: 'C_TIPS',
				    allowBlank: true
				},
				{
				    fieldLabel: '依赖查询控件编码',
				    name: 'C_SRC_ID',
				    allowBlank: true
				},
				{
					xtype: 'combobox',
				    fieldLabel: '<span class="required">✶</span>控件是否可见',
				    name: 'IS_SHOW',
				    displayField: 'name',
                    valueField: 'id',
                    value: 1,
                    store: DebtEleStore(json_show_type),
                    editable: false,
				    allowBlank: false
				}
        ]
    });
    if(config.edit){
    	form.down('textfield[name="C_CODE"]').setDisabled(true);
    }
    //初始化及回显
    form.getForm().setValues(config.data);
    var modeValue =  Ext.ComponentQuery.query('combobox[name="C_DISP_MODE"]')[0].getValue();
	var isMul = Ext.ComponentQuery.query('combobox[name="IS_MUL"]')[0];
	if(modeValue == "treecombobox"){
		isMul.setHidden(false);
	}else{
		isMul.setValue("0");
		isMul.setHidden(true);
	}
    return form;
};

function fieldCodeStore(q_id){
	var store = new Ext.data.Store({
        autoLoad: true,
        fields: ['id','code', 'name'],
        proxy: {
            type: 'ajax',
            url: '/sys-report/getFieldCodeStore',
            extraParams: {
            	Q_ID:q_id
            },
            reader: {
                type: 'json',
                root: 'list'
            }
        }
    });
	
	return store;
};

function fieldConfig(){
	var form=Ext.ComponentQuery.query('form#window_zdpz_contentForm')[0];
	var fieldCode = Ext.ComponentQuery.query('combobox[name="FIELD_CODE"]')[0].getValue();
	Ext.Ajax.request({
		method : 'POST',
		url : "/sys-report/getFieldConfigByCode",
		params : {
			fieldCode: fieldCode
		},
		async : false,
		success : function(response, options) {
//			// 获取返回的JSON，并根据gridid，获取表头配置信息
			var respText = Ext.util.JSON.decode(response.responseText);
			var fieldCodeConfig =  eval(respText.fieldList)[0];
			form.getForm().setValues(fieldCodeConfig);
		},
		failure : function(response, options) {
			
		}
	});
};


function conditionCodeStore(q_id){
	var store = new Ext.data.Store({
        autoLoad: true,
        fields: ['id','code', 'name'],
        proxy: {
            type: 'ajax',
            url: '/sys-report/getContidionCodeStore',
            extraParams: {
            	Q_ID:q_id
            },
            reader: {
                type: 'json',
                root: 'list'
            }
        }
    });
	return store;
};


function conditionConfig(){
	var form=Ext.ComponentQuery.query('form#window_tjpz_contentForm')[0];
	var conditionCode = Ext.ComponentQuery.query('combobox[name="C_CODE"]')[0].getValue();
	Ext.Ajax.request({
		method : 'POST',
		url : "/sys-report/getConditionConfigByCode",
		params : {
			conditionCode: conditionCode
		},
		async : false,
		success : function(response, options) {
//			// 获取返回的JSON，并根据gridid，获取表头配置信息
			var respText = Ext.util.JSON.decode(response.responseText);
			var conditionConfig =  eval(respText.conditionList)[0];
			form.getForm().setValues(conditionConfig);
		},
		failure : function(response, options) {
			
		}
	});
};
